package com.itheima.demo2recursion;

public class RecursionDemo2 {
    public static void main(String[] args) {
//        求n的阶乘
        int n=5;
        long result=factorial(n);
        long result2=factorial2(n);
        System.out.println(result2);
        System.out.println(result);
    }
    public static long factorial(int n){
        if(n==1){
            return 1;
        }else{
            return n*factorial(n-1);
        }
    }
    public static long factorial2(int n){
        if(n==1){
            return 1;
        }else{
            return n+factorial2(n-1);
        }
    }
}
